
/**
*  \file output.c
*
*  \brief
*
*  \author Michael J. Hohmann  <michael.hohmann@linde-mh.de>
*
*
*/

/*===============================================[ private includes  ]================================================*/
#include "output.h"
#include "../assertor/assertor.h"
#include "../pal/pal_mem.h"
#include "../mcu/mcu.h"
#include "../cancom/cancom.h"
#include "../output/output.h"

/*===============================================[ private defines   ]================================================*/

/*===============================================[ private datatypes ]================================================*/

/** Private variables */
struct output_private
{
    struct output_data_obj output_data; /* keep a copy of the output data for diagnostic and monitoring */
};

/*===============================================[ private variables ]================================================*/
static struct output_private output;

/*===============================================[ private functions ]================================================*/

/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/
RC output_initialize( void )
{
   
   pal_memzero( &output, sizeof output);

   return RC_SUCCESS;
}

void output_set( struct output_data_obj const * p_data )
{   
	static int temp = 0;
   ASSERTOR_PRE( NIL != p_data,"NIL is not allowed as data pointer." );

   /* digital outputs */
   mcu_set_output( mcu_output_FAN_CONTROLLER_OUT_LS_CPU_V,  p_data->fan_motor           );
   mcu_set_output( mcu_output_FAN_MOTOR_OUT_LS_CPU_V,       p_data->fan_controller      );

   mcu_set_output( mcu_output_BUZZER_OUT_LS_CPU_V,          p_data->buzzer             );
   mcu_set_output( mcu_output_ALARM_BUZZER_OUT_LS_CPU_V,    p_data->alarm_buzzer       );
   mcu_set_output( mcu_output_DC_LINK_PRECHAGE_EN_CPU_V,    p_data->precharge          );
   mcu_set_output( mcu_output_INV1_ENABLE_CPU_V,            p_data->inverter_1_enable  );       /**< enable  Fan73895  */
   mcu_set_output( mcu_output_INV2_ENABLE_CPU_V,            p_data->inverter_2_enable  );       /**< enable  Fan73895  */
   mcu_set_output( mcu_output_LED_0805_GE,                  p_data->led                );       /**< the led on board  */
   mcu_set_output( mcu_output_DCDC_CONTROL_CPU_V,           p_data->dcdc_control       );
   /*mcu_set_output( mcu_output_RESET_ERROR_CPU_V,          p_data->reset_error_cpu    );       */

   /* pwm outputs */
   mcu_set_pwm( mcu_pwm_contactor, p_data->main_contactor_pwm);
   // mcu_set_pwm( mcu_pwm_iso_valve, p_data->iso_valve_pwm );

   /* get DTC >= 200  */
   getDtcListOver_200(&p_data->vehicle_dtc[0]);

}

struct output_data_obj const *  output_get_current_data( void )
{
    return &output.output_data;
}

/*===============================================[ private functions ]================================================*/


/***********************************************************************************************************************
*                             Copyright 2019 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
